<!--
 * @Author: Rain
 * @Date: 2021-11-21 14:32:58
 * @LastEditTime: 2023/10/12 21:26:58
 * @Description: Do Something
-->
<template>
  <div class="app-container w-full h-full overflow-hidden">
    <!--工具栏-->
    <div class="head-container overflow-hidden h-full w-full flex flex-col">
      <div class="flex items-center flex-end search pb-10">
        <!-- 搜索 -->
        <!-- <label class="el-form-item-label">题型名称</label> -->
        <el-input
          v-model="query.typeName"
          clearable
          placeholder="题型名称"
          style="width: 185px"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <rrOperation :crud="crud" />
        <crudOperation :permission="permission" />
      </div>
      <div class="w-full flex-1 overflow-hidden">
        <el-table
          ref="table"
          v-loading="crud.loading"
          :data="crud.data"
          size="small"
          style="width: 100%"
          height="100%"
          @selection-change="crud.selectionChangeHandler"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column width="55" label="#" type="index" />
          <el-table-column prop="typeName" label="题型名称" align="center" />
          <el-table-column prop="typeDesc" label="题型说明" align="center" />
          <el-table-column prop="remark" label="备注" align="center" />
          <el-table-column prop="status" label="是否启用" align="center">
            <template slot-scope="scope">
              {{ dict.label.advert_status[scope.row.status] }}
            </template>
          </el-table-column>
          <el-table-column
            v-if="checkPer(['admin', 'examType:edit', 'examType:del'])"
            label="操作"
            align="center"
            width="170px"
          >
            <template slot-scope="{ row }">
              <div class="flex items-center">
                <udOperation :data="row" :permission="permission" />
                <el-button
                  v-if="0"
                  size="mini"
                  type="success"
                  style="margin-left: 5px"
                  icon="el-icon-document"
                  title="试题"
                  @click="viewSubject(row)"
                />
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!--分页组件-->
      <pagination />
    </div>
    <el-dialog
      :close-on-click-modal="false"
      :before-close="crud.cancelCU"
      :visible.sync="crud.status.cu > 0"
      :title="crud.status.title"
      width="500px"
    >
      <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
        <el-form-item label="题型名称" prop="typeName">
          <el-input
            v-model="form.typeName"
            style="width: 370px"
            placeholder="题型名称..."
          />
        </el-form-item>
        <el-form-item label="是否启用">
          <el-select v-model="form.status" filterable placeholder="请选择" class="w-full">
            <el-option
              v-for="item in dict.advert_status"
              :key="item.id"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="题型说明">
          <el-input
            v-model="form.typeDesc"
            type="textarea"
            style="width: 370px"
            placeholder="题型说明..."
          />
        </el-form-item>
        <el-form-item label="备注">
          <el-input
            v-model="form.remark"
            type="textarea"
            style="width: 370px"
            placeholder="备注"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="text" @click="crud.cancelCU">取消</el-button>
        <el-button
          :loading="crud.status.cu === 2"
          type="primary"
          @click="crud.submitCU"
        >确认</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import crudExamType from '@/api/examType'
import CRUD, { crud, form, header, presenter } from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import rrOperation from '@crud/RR.operation'
import udOperation from '@crud/UD.operation'

const defaultForm = {
  id: null,
  typeName: null,
  typeDesc: null,
  remark: null,
  status: null
}
export default {
  name: 'ExamType',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['advert_status'],
  cruds() {
    return CRUD({
      title: '题型类型',
      url: 'api/examType',
      idField: 'id',
      sort: 'id,desc',
      crudMethod: { ...crudExamType }
    })
  },
  data() {
    return {
      permission: {
        add: ['admin', 'examType:add'],
        edit: ['admin', 'examType:edit'],
        del: ['admin', 'examType:del']
      },
      rules: {
        typeName: [{ required: true, message: '请输入题型名称...' }]
      },
      queryTypeOptions: [{ key: 'typeName', display_name: '题型名称' }]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    viewSubject(row) {
      const { id } = row
      this.$http
        .post('/api/atmrExamType/create/examInfo', { atmrExamTypeId: id })
        .then((_) => {
          console.log(_)
        })
    }
  }
}
</script>

<style scoped></style>
